<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
    //1,数据运行机制
    var obj1={
        name:'name',
        x:{age:20}
        };
    var obj2=obj1;
    obj1=obj1.x;
    obj2.y=30;
    console.log(obj1,obj2);
    //11
    var ary=[12,23];
    function fn(ary){
      console.log(ary);
      ary[0]=100;
      ary=[100];
      ary[0]=0;
      console.log(ary);
    }
    fn(ary);
    console.log(ary);
    //111
    var n=10;
    function fn(){
      var n=20;
      function f(){
        n++;
        console.log(n);
      }
      f();
      return f;
    }
    var x=fn();
    x();
    x();
    console.log(n);
    
    //2,变量提升机制
      //a 基本测试
    var num=100;
    function test() {
        var num = 123;
        console.log(num);
    }
    test();        
    console.log(num);

      //b window测试
      function wins(){
        if("a" in window){//in 检测当前对象是否包含这个属性 返回boolean
            var a = 10;
        }
        console.log(a); 
    }
      wins();

      if(!"x" in window){
        var a = 10;
      }
      console.log(x);
      //c =
      
      var name='liLei';
      var fn =(function(name){
          var name='mike';
          return function (name){
            console.log(name);
          }
      })(name);
       fn();

      //d 不重复
      foo(); 
      var foo=100;
      function foo(){
          console.log(200);
        }
      foo(); 
      function foo(){
          console.log(300);
        }
      foo();
      var foo=500;
      function foo(){
          console.log(400);
        }
       foo(); 

     //e if
    
    f= function(){
        return true;
    }
    g=function(){
        return false;
    }
    ~function(){             //转false的值：0 , undefiend ,null ,""/'', NaN
      if(g() && [] == ![]){ // 空数组 转boolean 为true，![]=false []==false 都转数字 0==0
         f= function(){
             return false;
         }
         function g(){
             return true;
         }
      }
    }();
    console.log(f());
    console.log(g());

    //4,this
    var x=1,y=2;
    var point={
      x:10,
      y:20,
      moveTo:function(x,y){
          var mx=function(x){
             this.x=x;
          }
          var my=function(y){
             this.y=y;
          }
          mx();
          my();
      }
  }
 point.moveTo(100,200);
 console.log(point.x,point.y);
 console.log(x,y);

    </script>
</body>
</html>